package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseAttrInfo;
import com.atguigu.gmall.model.product.BaseCategory1;
import com.atguigu.gmall.model.product.BaseCategory2;
import com.atguigu.gmall.model.product.BaseCategory3;
import com.atguigu.gmall.product.service.ManagerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *
 */
@RestController
@RequestMapping("/admin/product")
@Api(tags = "后台商品管理")
//@CrossOrigin
public class BaseManagerController {

    //自动注入
    @Autowired
    private ManagerService managerService;



    /**
     admin/product/getAttrValueList/{attrId}
     /admin/product/getAttrValueList/{attrId}
     * 根据平台属性Id 获取到平台属性值集合
     */
    @ApiOperation(value = "根据平台属性Id 获取到平台属性值集合")
    @GetMapping("/getAttrValueList/{attrId}")
    public Result getAttrValueList(@PathVariable Long attrId){

        //调用Service层的方法实现该功能
        BaseAttrInfo baseAttrInfo =  managerService.getAttrValueList(attrId);

        return Result.ok(baseAttrInfo.getAttrValueList());
    }



    /**
     admin/product/saveAttrInfo
     * 保存-修改平台属性

     */
    @PostMapping("/saveAttrInfo")
    public Result saveAttrInfo(@RequestBody BaseAttrInfo baseAttrInfo){

        managerService.saveAttrInfo(baseAttrInfo);

        return Result.ok();
    }



    /**

     /admin/product/attrInfoList/{category1Id}/{category2Id}/{category3Id}
     * 根据分类Id 获取平台属性集合

     */
    @ApiOperation(value = "根据分类Id 获取平台属性集合")
    @GetMapping("/attrInfoList/{category1Id}/{category2Id}/{category3Id}")
    public Result attrInfoList(@PathVariable Long category1Id,
                               @PathVariable Long category2Id,
                               @PathVariable Long category3Id){

        List<BaseAttrInfo> baseAttrInfoList=managerService.attrInfoList(category1Id,category2Id,category3Id);

        return Result.ok(baseAttrInfoList);
    }





    /**
     /admin/product/getCategory3/{category2Id}
     * 获取三级分类数据

     */
    @ApiOperation(value = "获取三级分类数据")
    @GetMapping("/getCategory3/{category2Id}")
    public Result getCategory3(@PathVariable Long category2Id){

        //调用service层方法
        List<BaseCategory3> baseCategory3List = managerService.getCategory3(category2Id);

        return Result.ok(baseCategory3List);
    }


    /**
     /admin/product/getCategory2/{category1Id}
     * 获取二级分类数据

     */
    @ApiOperation(value = "获取二级分类数据")
    @GetMapping("/getCategory2/{category1Id}")
    public Result getCategory2(@PathVariable Long category1Id){

        //调用service层的方法
        List<BaseCategory2> baseCategory2List =  managerService.getCategory2(category1Id);

        return Result.ok(baseCategory2List);
    }




    /**
     获取一级分类列表数据
     * admin/product/getCategory1

     */
    @ApiOperation(value = "获取一级分类列表数据")
    @GetMapping("/getCategory1")
    public Result getCategory1(){

        //调用service层方法
        List<BaseCategory1>  category1List = managerService.getCategory1();

        return Result.ok(category1List);
    }

}
